package com.leather.market.exception;

import com.leather.common.exception.GlobalException;
import com.leather.common.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;


@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {
    @ExceptionHandler(value = Exception.class)
    public Result exceptionHandler(HttpServletRequest request, Exception e) {

        if (e instanceof GlobalException) {
            GlobalException ex = (GlobalException) e;
            return Result.error(ex.getCm());
        } else {
            e.printStackTrace();
            //开发的时候
            // return Result.error(CodeMsg.SERVER_ERROR);
            return Result.exception(600000, e.getMessage());
        }
    }
}
